package cn.outsourcing.supermarket.provider;

import org.apache.ibatis.jdbc.SQL;

/**
 * 订单 SQL 构造器
 *
 * @author gzkemays
 * @since 2021/10/24 2:41
 */
public class OrderProvider {
  public String getOrderTypeCount() {
    return new SQL() {
      {
        SELECT("count(1) as toDelivery")
            .SELECT("(" + getToPay() + ") as toPay")
            .SELECT("(" + getToReceive() + ") as toReceive")
            .FROM("hiolabs_order")
            .WHERE("user_id = ${userId}")
            .AND()
            .WHERE("is_delete = 0")
            .AND()
            .WHERE("order_type < 7")
            .AND()
            .WHERE("order_status = '201'");
      }
    }.toString();
  }

  private String getToPay() {
    return new SQL() {
      {
        SELECT("count(1)")
            .FROM("hiolabs_order")
            .WHERE("user_id = ${userId}")
            .AND()
            .WHERE("is_delete = 0")
            .AND()
            .WHERE("order_type < 7")
            .AND()
            .WHERE("order_status in ('101','801')");
      }
    }.toString();
  }

  private String getToReceive() {
    return new SQL() {
      {
        SELECT("count(1)")
            .FROM("hiolabs_order")
            .WHERE("user_id = ${userId}")
            .AND()
            .WHERE("is_delete = 0")
            .AND()
            .WHERE("order_type < 7")
            .AND()
            .WHERE("order_status = '301'");
      }
    }.toString();
  }
}
